<?php
/**
 * Created by PhpStorm.
 * User: gyccvvh
 * Date: 2018-06-28
 * Time: 14:15
 */

namespace app\merchant\model;


use think\Model;

class Goods extends Model{
    public function checkForm($data, $scene = '') {
        $validate = validate($this->name);
        $res = $validate->scene($scene)->check($data);
        if (!$res) {
            return $validate->getError();
        } else {
            return false;
        }
    }
    public function getBy($mer_id,$where,$val){
        $res = $this->where("g.mer_id",$mer_id)->where($where,$val)->alias("g")
            ->join("GoodsProps gp","gp.good_id = g.id","LEFT")
            ->join("Intent i","i.id = gp.intended","LEFT")
            ->join("Scene s","s.id = gp.scene","LEFT")
            ->join("Season ss","ss.id = gp.season","LEFT")
            ->join("Company c","c.id = gp.company","LEFT")
            ->field("g.*,gp.company,gp.season,gp.code,gp.material,gp.scene,gp.intended,gp.style,
            i.name as intent_name,s.name as scene_name,c.name as company_name,ss.name as season_name")
            ->select();
        if(!$res) {
            return false;
        }
        return $res;
    }

    public function getById($mer_id,$id)
    {
        $res = $this->getBy($mer_id, "g.id", $id);
        if (!$res) {
            return false;
        }
        return $res[0];
    }



}